/**
 * @Author MrsGuo
 * version 1.0
 * @Date 2023-08-03 15:13
 */
package com.cl.erp_2301.Service.impl;

import com.cl.erp_2301.Service.MenuService;
import com.cl.erp_2301.dto.MenuDTO;
import com.cl.erp_2301.mapper.MenuMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Resource
    private MenuMapper menuMapper;

    @Override
    public List<MenuDTO> selectMenuList(int uuid) {
        List<MenuDTO> menuDTOList = menuMapper.selectMenuList(uuid);
        List<MenuDTO> newList = new ArrayList<MenuDTO>();
        for (MenuDTO menu : menuDTOList) {
            if (menu.getPid().equals(0)) {
                newList.add(menu);
            }
        }
        for (MenuDTO parentMenu : newList) {
            parentMenu.setList(new ArrayList<>());
            for (MenuDTO menu : menuDTOList) {
                if (menu.getPid() == parentMenu.getId()) {
                   parentMenu.getList().add(menu);
                }
            }
        }


        return newList;
    }
}
